package pub.guoxin.oops.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.querydsl.core.annotations.QueryEntity;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.mongodb.morphia.annotations.Entity;
import org.mongodb.morphia.annotations.Id;
import pub.guoxin.oops.tidy.LocalDateTimeDeserializer;
import pub.guoxin.oops.tidy.LocalDateTimeSerializer;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * Created by guoxin on 17-10-18.
 */
@Data
@Entity
@QueryEntity
@JsonInclude(JsonInclude.Include.NON_NULL)
@NoArgsConstructor
public class RealTimeCommunication implements Serializable {

    private static final long serialVersionUID = 405653126397547786L;
    /**
     * 设备串号 SN
     */
    @Id
    private String id;
    /**
     * 分组Id
     */
    private String groupId;

    private String companyId;
    /**
     * 备注
     */
    private String remark;
    /**
     * 电池电量
     */
    private Float batteryLevel;
    /**
     * 版本号
     */
    private Integer version;
    /**
     * 经度
     */
    private Float longitude;
    /**
     * 纬度
     */
    private Float latitude;
    /**
     * 时间戳
     */
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime dateTime;


    public RealTimeCommunication(Communication communication) {
        this.batteryLevel = communication.getBatteryLevel();
        this.id = communication.getSn();
        this.dateTime = communication.getDateTime();
        this.version = communication.getVersion();
    }

}
